import 'package:dartkit/dartkit.dart';
import 'package:test/test.dart';

final _time1 = DateTime.now().subtract(Duration(minutes: 60));
final _time2 = DateTime.now().subtract(Duration(minutes: 30));
final _time3 = DateTime.now().subtract(Duration(minutes: 20));
final _time4 = DateTime.now().subtract(Duration(minutes: 2));

void main() {
  test("开始和结束的顺序", () {
    // 创建一个结束时间更早的番茄，发生了逻辑错误
    expect(
        () => Pomo(
              id: 1,
              period: Period(_time2, _time1),
              title: "",
              summary: "",
            ),
        isBug);
  });

  test("序列化与反序列化测试", () {
    // 将一个对象序列化后反序列化
    final pomo = Pomo(
      id: 1,
      period: Period(
          DateTime.now().subtract(Duration(minutes: 25)), DateTime.now()),
      title: "番茄",
      summary: "番茄总结",
    );
    final recover = Pomo.fromRaw(pomo.toJson());
    // 对比后发现各项参数都没有变化
    expect(pomo.period, recover.period);
    expect(pomo.title, recover.title);
    expect(pomo.summary, recover.summary);
    expect(pomo.id, recover.id);
  });

  test("相等测试", () {
    // 使用相同数据创建两个番茄，它们是相等的
    final now = DateTime.now();
    final pomo1 = Pomo(
      id: 1,
      period: Period(now.subtract(Duration(minutes: 25)), now),
      title: "番茄",
      summary: "番茄总结",
    );
    final pomo2 = Pomo(
      id: 1,
      period: Period(now.subtract(Duration(minutes: 25)), now),
      title: "番茄",
      summary: "番茄总结",
    );
    expect(pomo1 == pomo2, isTrue);
    // 有一个地方修改了之后，就不相等了
    pomo2.title = "修改";
    expect(pomo1 == pomo2, isFalse);
  });
}
